Automatic Update Checking System

by Noble Bell



NL136 Home

::::::::::::::::::::::::::::::::::::::::::::::::::::

Eddie Version 6

Comalspeech.dll

Point-and-Click

Dr. Strange Text

Length of Internet File

Automatic File Updating

API Corner

Wire 1.0 on the Horizon

::::::::::::::::::::::::::::::::::::::::::::::::::::

Submission Guildlines

Newsletter Help

Index

Give Auto Updating a Try!

So, you want your users to update their software?

The subject of automatic updating has been touched on before in an article by John Richardson in Newsletter #112. I have taken it a step or two further with the addition of some features.

The subroutine which I authored (see source code below), when placed in your LB code, will allow you to let users automatically check for and download any new updates to your software. Interested in how it is done? Then read on!

Update Method Requires a Single DLL

To achieve what I am talking about we make use of a single Windows dll called, “URLmon.dll”. In this dll there is a function called, “URLDownloadToFileA” that will handle all of the file downloading from the Internet.

I will not go into detail on how this function is used because as I mentioned earlier that it was already covered in some detail in newsletter #112 by John Richardson and also by Alyce Watson. [Also, see this API Corner article authored by Alyce Watson in the current issue. --Ed]

First off, there are some things that you have to do with each and every program that you add this functionality to:

  1. You have to create a special text file that contains the current version of the program. I usually call it the same name as the executable but with a .txt extension.

  2. Within this text file, that I will call “proggie.txt” for this demo there should only be one line in it. (the current version number of your software) 3.25 for this demo.

  3. The best place to keep this file is within the directory path that the executable is located in.

  4. You will need to have a website that you can place file on.

  5. Place two files on the website: one is a text file that contains the next version of the software and the other file is a zip file that is the actual updated program.

  6. The text file that is on the website, in this demo, is named “proggieupdate.txt” and in it contains the next version of the software: 4.25

  7. The other file, the zip file, I called proggie.zip. It contains a new text file with a new version number in it. (For the demo of course).

Phew! Now that all of that is done I will explain how it all works using the example program that I have enclosed (with comments of course).

Overview of Enclosed Program

When the program asks the user if they want to check for an update and the user answers yes then this is what happens:

  1. The program goes to the internet and downloads the file that is contained in the variable called: urlfile$. In this demo it is: "[http://www.noblebell.com/proggieupdate.txt]"

  2. The program downloads this file to a local machine and that information is contained in the variable called: localfile$. In this demo it is: “c:\proggieupdate.txt”

  3. Once the file gets downloaded, assuming no errors, the program will then open the text file, “proggieupdate.txt”, and put the version number into a local variable called: internetVersion$. In this demo it is: “4.25”

  4. After the program opens the downloaded file it will then open the local file, the one that comes with your software and is called, “proggie.txt” in this example, it reads its version number and places it into a local variable called, currentVersion$. In this demo it is: “3.25”

  5. After it has both values it will compare the two and see if the value in internetVersion$ is greater than the value in currentVersion$. If it is greater then we tell the user there is an update and that they can download it. Otherwise we tell the user they are using the most up-to-date version of the software.

  6. Assuming that there was an update available then the process is repeated except this time we download the zip file and after the zip file is downloaded we exit the demo and unzip the zip file into the path that the program is in.

When you re-run the program and check for an update again you will notice that it says that it is up-to-date.

Really cool uh!? That is all there is too it.

I have enclosed the demo files in this article but if you would like you can download them from my website at [http://www.noblebell.com] . If you have any comments or suggestions you can voice them at the same website.

--Noble Bell http://www.noblebell.com


Auto Update Source Code

' Automatic Update Checking System
' Last Revised: August 3, 2005
' Noble D. Bell
' www.noblebell.com

nomainwin


[setup.main.Window]

    '-----Begin code for #main

    WindowWidth = 425
    WindowHeight = 145
    UpperLeftX=int((DisplayWidth-WindowWidth)/2)
    UpperLeftY=int((DisplayHeight-WindowHeight)/2)


    '-----Begin GUI objects code

    statictext #main.statictext1, "Automatic Update Checker", 120,  17, 195,  20
    statictext #main.statictext2, "Do you want to check for a later version?",  85,  42, 255,  20
    button #main.btnYes,"YES",[btnYesClick], UL,  85,  77,  96,  25
    button #main.btnNo,"No",[btnNoClick], UL, 225,  77,  96,  25

    '-----End GUI objects code

    open "UPDATE" for window_nf as #main
    print #main, "font ms_sans_serif 10"
    print #main, "trapclose [quit]"


[mainloop]
    wait


[quit]
    close #main
    end

[btnNoClick]
    goto [quit]

[btnYesClick]
    call CheckInternetForUpdate
    goto [mainloop]



' this routine handles all the update checking
Sub CheckInternetForUpdate

    open "URLmon" for dll as #url

    urlfile$ = "http://www.noblebell.com/proggieupdate.txt"   ' the internet location of the download file
    localfile$ = "c:\proggieupdate.txt"                       ' the location on the local machine to store download


    ' download the file from the website to the local host
    calldll #url, "URLDownloadToFileA",_
    0 as long,_         'Leave this setting!
    urlfile$ as ptr,_
    localfile$ as ptr,_
    0 as long,_         'Must be 0.
    0 as long,_         'Callback address.
    ret as long

    ' if there is any sort of error the dll will return a non-zero value
    if ret <> 0 then
        notice "There was an error in checking for an update. Aborted!"
        close #url
        exit sub
    end if

    ' ok, we have the downloaded file. now let's check it against the program's version

    ' open the downloaded file from the internet and get the version number stored in it
    open "c:\proggieupdate.txt" for input as #1
    input #1, internetVersion$
    close #1

    ' open the program's file and get the version number stored in it
    open "c:\proggie.txt" for input as #1
    input #1, currentVersion$
    close #1

    ' compare the two versions and see if the internet version is greater than the current version. if it
    ' is then we prompt the user to download the later version. Otherwise, well tell the user that they have
    ' the latest version of the code.
    if internetVersion$ > currentVersion$ then
        txt$ = ""
        txt$ = "There is a newer version available."+chr$(13)
        txt$ = txt$ + "Your current version is " + currentVersion$+chr$(13)+chr$(13)
        txt$ = txt$ + "The latest version is " + internetVersion$+chr$(13)+chr$(13)
        txt$ = txt$ + "Do you want to download the update?"+chr$(13)

        confirm txt$;answer$
        if answer$ = "no" then exit sub

        ' download the latest version from the internet and store it on the local drive for processing
        urlfile$ = "http://www.noblebell.com/proggie.zip"
        localfile$ = "c:\proggie.zip"

        calldll #url, "URLDownloadToFileA",_
        0 as long,_         'Leave this setting!
        urlfile$ as ptr,_
        localfile$ as ptr,_
        0 as long,_         'Must be 0.
        0 as long,_         'Callback address.
        ret as long

        if ret <> 0 then
            notice "There was an error in checking for an update. Aborted!"
            close #url
            exit sub
        end if

        notice "Download Complete"+chr$(13)+"Please exit this program and install it."

    else
        txt$ = "CURRENT"+chr$(13)
        txt$ = txt$ + "You have version " + currentVersion$ + " which is"+chr$(13)
        txt$ = txt$ + "the latest version."

        notice txt$
    end if

    close #url

    kill "c:\proggieupdate.txt"

End Sub


NL136 Home

::::::::::::::::::::::::::::::::::::::::::::::::::::

Eddie Version 6

Comalspeech.dll

Point-and-Click

Dr. Strange Text

Length of Internet File

Automatic File Updating

API Corner

Wire 1.0 on the Horizon

::::::::::::::::::::::::::::::::::::::::::::::::::::

Submission Guildlines

Newsletter Help

Index